<%-- 
    Document   : doSignup
    Created on : Nov 23, 2012, 2:11:07 AM
    Author     : ADMIN
--%>

<%@page import="com.DAO.Customer"%>
<%@page import="com.DAO.CustomerDAO"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>;
<%@page language="java" import="java.util.*,java.awt.*,dao.*;

        "%>;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<%
    int erro = 0;
    request.setCharacterEncoding("UTF-8");

    String dongy = (String) request.getParameter("dongY");
    String ho = (String) request.getParameter("ho");
    String tenDem = (String) request.getParameter("tenDem");
    String ten = (String) request.getParameter("ten");
    String taiKhoan = (String) request.getParameter("taiKhoan");
    String password = (String) request.getParameter("password");
    String rePassword = (String) request.getParameter("rePassword");
    String gioiTinh = (String) request.getParameter("gioiTinh");
    String ngay = (String) request.getParameter("ngay");
    String thang = (String) request.getParameter("thang");
    String nam = (String) request.getParameter("nam");
    String thanhPho = (String) request.getParameter("thanhPho");
    String email = (String) request.getParameter("email");

    if (dongy.equals("")) {
        erro = 1;
        //  response.sendRedirect("CustomerSignup.jsp?number=1");

    } else {
        erro = 0;
    }
    if (ten.equals("")) {
        erro = 2;
        //     response.sendRedirect("CustomerSignup.jsp?number=2");
    } else {
        erro = 0;
    }
    if (taiKhoan.equals("")) {
        erro = 3;
        //     response.sendRedirect("CustomerSignup.jsp?number=3");
    } else {
        erro = 0;
    }
    if (password.equals("")) {
        erro = 4;
        //   response.sendRedirect("CustomerSignup.jsp?number=4");                 
    } else {
        erro = 0;
    }
    if (rePassword.equals(password) == false) {
        erro = 5;
        //       response.sendRedirect("CustomerSignup.jsp?number=5");    
    } else {
        erro = 0;
    }
    if (ngay.equals("0") | thang.equals("0") | nam.equals("0")) {
        erro = 6;
        //        response.sendRedirect("CustomerSignup.jsp?number=6");
    } else {
        erro = 0;
    }
    if (email.equals("")) {
        erro = 7;
        //  response.sendRedirect("CustomerSignup.jsp?number=7");
    } else {
        erro = 0;
    }

    if (erro == 0) {

        //SqlConnect connect = new SqlConnect();
        Connection con = null;
        String dbClass = "com.mysql.jdbc.Driver";
        String dbURL = "jdbc:mysql://localhost:3306/banhang?user=root&password=&useUnicode=true&characterEncoding=UTF-8";

        Class.forName(dbClass);
        con = DriverManager.getConnection(dbURL);

        Customer custome = new Customer();
        custome.setName(ho + " " + tenDem + " " + ten);
        custome.setEmail(email);
        custome.setUserName(taiKhoan);
        custome.setPassword(password);
        custome.setAddress(thanhPho);
        custome.setBank_code("");
        custome.setIden_num("098898xxxx0");
        // Customer a = new Customer(1, "hung", "123", "bang@gmail.com", "bang", "hanoi", 12, 12);
        CustomerDAO cdao = new CustomerDAO();
        Customer cus = cdao.addNew(custome);

        if (cus != null) {
            response.sendRedirect("customerLogin.jsp");
            con.close();
        } else {
            response.sendRedirect("customerSignup.jsp?number=8");
        }
    } else {
        response.sendRedirect("customerSignup.jsp?number=9");
    }



//                                         










%>
